import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from './router'
import {postRequest} from './utils/api.js'
import {getRequest} from './utils/api.js'
import {deleteRequest} from "./utils/api.js";
import store from './store/index'
import {initMenu} from "./utils/menu";
import 'font-awesome/css/font-awesome.css'
import {hasPermission} from "./utils/permission";

router.beforeEach((to,from,next)=>{

  if(window.sessionStorage.getItem("token")){
    console.log("init.......")
    initMenu(router,store)
    next()
  }else{
    if(to.path=="/"){
      console.log("111")
      next()
    }else{
      console.log("2222")
      next('/?redirect='+to.path)
    }

  }
})
Vue.config.productionTip = true

Vue.use(ElementUI)
Vue.prototype.hasPermission = hasPermission
Vue.prototype.postRequest = postRequest
Vue.prototype.getRequest = getRequest
Vue.prototype.deleteRequest = deleteRequest

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
